<?php   // $Id: client.php 200 2008-06-05 22:21:42Z pcoustillas $ ?>
<?php
/*Copyright (C) 2003-2004 Guy Hendrickx
Licensed under the terms of the GNU  General Public License:http://www.opensource.org/licenses/gpl-license.php
File Authors:Guy Hendrickx
Modification : Pierre Coustillas*/

require_once(dirname(__FILE__) ."/verif_client.php");
require_once(dirname(__FILE__) ."/../include/config/common.php");
require_once(dirname(__FILE__) ."/../include/config/var.php");
require_once(dirname(__FILE__) ."/../include/language/fr.php");
require_once(dirname(__FILE__) ."/../include/utils.php");

$conf_xml=simplexml_load_file(dirname(__FILE__) . '/../include/config.xml');
$theme=$conf_xml->generale->theme;
?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="fr" lang="fr">
  <head>
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
	<title>Connection à OpenDCF</title>
	<link rel="stylesheet" type="text/css" href="../include/themes/<?php echo "$theme";?>/style.css" />
	<link rel="shortcut icon" type="image/x-icon" href="../image/favicon.ico" />

	<script type="text/javascript" language="javascript">
	function verif_form()
	{
		if (verifier('client','black','pass','carac_spec#vide','pass_new','carac_spec#vide','pass_new2','carac_spec#vide'))
		{
			document.client.submit();
		} else {
			alert("<?php aff_lang('Une des valeurs saisie n\'est pas correct.\nMerci de corriger avant de poursuivre.') ?>")	
		}
	}
	</script>
	<script language="javascript" src="../javascripts/verifier_form.js" type="text/javascript"></script>


</head>
<body>

<?php
//variables a modifier afin de parametrer l'affichage de l'interface client.
//
$devis_auth = "ok";//ok permet l'affichage des devis
$bon_auth = "ok";//ok permet l'affichage des bons de commnde
$fact_auth = "ok";//ok permet l'afichage des factures
$change_mdp = "ko";//ok permet au client de changer son mot de passe
$lang = $_SESSION['lang'];




$sql = "SELECT * FROM ${tblpref}client WHERE num_client = " . $_SESSION['num_client'];
$req = mysql_query($sql);
$data = mysql_fetch_array($req);
$login = $data['login'];
$nom = $data['nom'];
$nom2 = $data['nom2'];
$num_client = $data['num_client'];


if (isset($_GET['msg']))
{
//c'est certainement que le client à mis à jour son mot de passe.
	echo "<h2>" . $_GET['msg'] . "</h2>";
}
?>


<h6><?php echo "$nom  $nom2"; ?></h6>
<center>
<hr/>

<table border="0" align="center">
	<tr>
		<td class="page" align="center">
		<center>
			<?php
			
			if ($devis_auth == "ok") {
				$sql3 = "SELECT num_dev, tot_htva, tot_tva, DATE_FORMAT(date,'%d/%m/%Y') AS date, nom
					FROM ${tblpref}devis RIGHT JOIN ${tblpref}client  on ${tblpref}devis.client_num = num_client
					WHERE client_num = '$num_client' AND resu = '0' ORDER BY ${tblpref}devis.num_dev DESC ";
				$req3 = mysql_query($sql3) or die("Erreur selection devis !<br/>$sql3<br/>" . mysql_error());
				?>
				<table class="boiteaction">
					<caption>
						<?php echo $lang_devis_pluriel; ?>
					</caption>
					<tr>
						<th width="40"><?php echo $lang_numero; ?></th>
						<th width="110"><?php echo $lang_date; ?></th>
						<th width="110"><?php echo $lang_total_h_tva; ?></th>
						<th width="110"><?php echo $lang_total_ttc; ?></th>
						<th width="110"><?php echo $lang_imprimer; ?></th>
						<th width="110"><?php echo $lang_accepter ?> </th>
						<th width="110"><?php echo $lang_refu ?></th>
					</tr>
					<?php
					while($data = mysql_fetch_array($req3))
					{
						$num_dev = $data['num_dev'];
						$total = $data['tot_htva'];
						$tva = $data['tot_tva'];
						$date = $data['date'];
						$nom = $data['nom'];
						$ttc = $total + $tva ;
						?>
						<tr>
							<td class="<?php echo couleur_alternee (); ?>"><?php echo $num_dev; ?></td>
							<td class="<?php echo couleur_alternee (FALSE); ?>"><?php echo $date; ?></td>
							<td class="<?php echo couleur_alternee (FALSE); ?>" style="text-align:right"><?php echo montant_financier ($total); ?></td>
							<td class="<?php echo couleur_alternee (FALSE); ?>" style="text-align:right"><?php echo montant_financier ($ttc); ?></td>
							<td class="<?php echo couleur_alternee (FALSE); ?>"> 
								<a href="../fpdf/devis_pdf.php?num_dev=<?php echo $num_dev; ?>&amp;pdf_user=client">
									<img src="../image/imprimante.png" alt="<?php echo $lang_imprimer; ?>" align="middle" border="0" />
								</a>
							</td>
						
							<td class="<?php echo couleur_alternee (FALSE); ?>">
								<a href="pre_convert.php?num_dev=<?php echo $num_dev ?>&amp;login=<?php echo $login ?>">
									<img src="../image/ok_kde.png" align="middle" border="0" alt="ok"/>
								</a>
							</td>
							<td class="<?php echo couleur_alternee (FALSE); ?>">
								<a href="refu_devis.php?num_dev=<?php echo $num_dev ?>&amp;login=<?php echo $login ?>">
									<img src="../image/delete.png" align="middle" border="0" alt="refus"/>
								</a>
							</td>
						</tr>
					<?php
					}
					?>
				</table>
				<br/>
				<br/>
			<?php
			}




			if ($bon_auth == "ok") { 
				?> 
				<table class="boiteaction">
					<caption><?php echo $lang_commandes; ?></caption>
				<?php  
				$sql2 = "SELECT num_bon, tot_htva, tot_tva, DATE_FORMAT(date,'%d/%m/%Y') AS date, nom 
						FROM ${tblpref}bon_comm RIGHT JOIN ${tblpref}client on ${tblpref}bon_comm.client_num = num_client
						WHERE client_num = '$num_client' ORDER BY ${tblpref}bon_comm.num_bon DESC ";
				$req2 = mysql_query($sql2) or die("Erreur selection des bons !<br/>$sql2<br/>" . mysql_error());
				?>
					<tr> 
						<th width="40"><?php echo $lang_numero; ?> </th>
						<th width="110"><?php echo $lang_date; ?></th>
						<th width="110"><?php echo $lang_total_h_tva; ?></th>
						<th width="110"><?php echo $lang_total_ttc; ?></th>
						<th width="110"><?php echo $lang_imprimer; ?></th>
						<th width="110">&nbsp;</th>
						<th width="110">&nbsp;</th>
					</tr>
					<?php
					while($data = mysql_fetch_array($req2))
					{
						$num_bon = $data['num_bon'];
						$total = $data['tot_htva'];
						$tva = $data['tot_tva'];
						$date = $data['date'];
						$nom = $data['nom'];
						$ttc = $total + $tva ;

						?>
						<tr>
							<td class='<?php echo couleur_alternee (TRUE); ?>'><?php echo $num_bon; ?></td>
							<td class='<?php echo couleur_alternee (FALSE); ?>'><?php echo $date; ?></td>
							<td class='<?php echo couleur_alternee (FALSE); ?>' style="text-align:right"><?php echo montant_financier($total); ?></td>
							<td class='<?php echo couleur_alternee (FALSE); ?>' style="text-align:right"><?php echo montant_financier($ttc); ?></td>
							<td class='<?php echo couleur_alternee (FALSE); ?>'>
								<form action="../fpdf/bon_pdf.php" method="post">
									<input type="hidden" name="num_bon" value="<?php echo $num_bon; ?>" />
									<input type="hidden" name="nom" value="<?php echo $nom; ?>" />
									<input type="image" src="../image/imprimante.png " alt="imprimer" />
								</form>
							</td>
							<td>&nbsp;</td>
							<td>&nbsp;</td>
						</tr>
						<?php
					}
					?>
					</table>
				<br/><br/>
			<?php
			}


			if ($fact_auth == "ok") {
				$sql = "SELECT num, DATE_FORMAT(date_fact,'%d/%m/%Y') AS date_fact,  total_fact_ttc, payement 
							FROM ${tblpref}facture
							WHERE CLIENT = '$num_client'"
							." ORDER BY 'num' DESC";
				$req = mysql_query($sql);
				?>
				<table class="boiteaction">
					<caption><?php echo $lang_factures; ?></caption>
					<tr>
						<th width="40"><?php echo $lang_numero; ?></th>
						<th width="110"><?php echo $lang_date; ?></th>
						<th width="110"><?php echo $lang_tot_ttc; ?></th>
						<th width="110"><?php echo $lang_pay; ?></th>
						<th width="110"><?php echo $lang_imprimer; ?></th>
						<th width="110">&nbsp;</th>
						<th width="110">&nbsp;</th>
					</tr>
					<?php
				
					while($data = mysql_fetch_array($req))
					{
					$payement = $data['payement'];
					$num = $data['num'];
					$total = $data['total_fact_ttc'];
					$date_fact = $data['date_fact'];
					?>
						<tr> 
							<td class='<?php echo couleur_alternee (); ?>'><?php echo $num; ?></td>
							<td class='<?php echo couleur_alternee (FALSE); ?>'><?php echo $date_fact; ?></td>
							<td class='<?php echo couleur_alternee (FALSE, "nombre"); ?>'><?php echo montant_financier($total); ?></td>
							<td class='<?php echo couleur_alternee (FALSE); ?>'><?php echo $payement; ?></td>
							<td class='<?php echo couleur_alternee (FALSE); ?>'> 
								<form action="../fpdf/fact_pdf.php" method="post">
									<input type="hidden" name="client" value="<?php echo $num_client; ?>" />
									<input type="hidden" name="num" value="<?php echo $num; ?>" />
									<input type="image" src="../image/imprimante.png" alt="imprimer" />
								</form>
							</td>
							<td colspan="2">&nbsp;</td>
						</tr>
						<?php
					}
					?>
				</table>
			<br/><br/>
			
			<?php
			}

			if ($change_mdp=="ok")
			{
			?>
			<form action="client_update.php" method="post" name="client" id="client">
			<table class="boiteaction">
				<caption>
				<?php echo "$lang_chng_mdp"; ?>
				</caption>
				<tr>
					<td class="texte0"><?php echo $lang_login; ?></td>
					<td><input name="login" type="text" readonly="readonly" value="<?php echo $login ?>"  /></td>
				</tr>
				<tr>
					<td class="texte0"><div id="pass"><?php echo $lang_motdepasse_ancien; ?></div></td>
					<td class="texte0"><input name = "pass" type="text" /> </td>
				</tr>
				<tr>
					<td class="texte0"><div id="pass_new"><?php echo $lang_motdepasse_nouveau; ?></div></td>
					<td class="texte0"><input name="pass_new" type="text" /> </td>
				</tr>
				<tr>
					<td class="texte0"><div id="pass_new2"><?php echo $lang_motdepasse_verification; ?></div></td>
					<td class="texte0"><input name="pass_new2" type="text" /> </td>
				</tr>
				<tr>
					<td class="submit" colspan="2">
						<input type="button" value="<?php echo $lang_motdepasse_changer; ?>" onclick="verif_form()" /> 
						<input type="reset" value="<?php echo $lang_annuler; ?>" />
						<input name="num_client" type="hidden" value='<?php echo $_SESSION['num_client']; ?>' />
					</td>
				</tr>
			</table>
			</form>

			<?php
			}
			?>

		</center>

		</td>
	</tr>
	
</table>
			
<br/><br/>
<a href='logout.php'><?php echo $lang_sortir ?></a>
<br/><br/>


</center>


<hr/>
</body>
</html>





